package cn.iocoder.yudao.module.digital.dal.mysql.projects;

import cn.iocoder.yudao.framework.common.pojo.PageResult;
import cn.iocoder.yudao.framework.mybatis.core.mapper.BaseMapperX;
import cn.iocoder.yudao.framework.mybatis.core.query.LambdaQueryWrapperX;
import cn.iocoder.yudao.module.digital.controller.admin.projects.vo.ProjectsPageReqVO;
import cn.iocoder.yudao.module.digital.dal.dataobject.projects.ProjectsDO;
import com.baomidou.mybatisplus.extension.handlers.JacksonTypeHandler;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Results;
import org.apache.ibatis.annotations.Result;
import org.apache.ibatis.annotations.Select;
import org.apache.ibatis.type.JdbcType;

/**
 * 项目 Mapper
 *
 * @author cxl
 */
@Mapper
public interface ProjectsMapper extends BaseMapperX<ProjectsDO> {

    default PageResult<ProjectsDO> selectPage(ProjectsPageReqVO reqVO) {
        return selectPage(reqVO, new LambdaQueryWrapperX<ProjectsDO>()
                .likeIfPresent(ProjectsDO::getName, reqVO.getName())
                .eqIfPresent(ProjectsDO::getType, reqVO.getType())
                .eqIfPresent(ProjectsDO::getOrganizer, reqVO.getOrganizer())
                .likeIfPresent(ProjectsDO::getOrganizerOther, reqVO.getOrganizerOther())
                .eqIfPresent(ProjectsDO::getLevel, reqVO.getLevel())
                .eqIfPresent(ProjectsDO::getAuthor, reqVO.getAuthor())
                .likeIfPresent(ProjectsDO::getMember, reqVO.getMember())
                .betweenIfPresent(ProjectsDO::getProjectStartTime, reqVO.getProjectStartTime())
                .betweenIfPresent(ProjectsDO::getProjectEndTime, reqVO.getProjectEndTime())
                .eqIfPresent(ProjectsDO::getStatus, reqVO.getStatus())
                .eqIfPresent(ProjectsDO::getEvidenceUrl, reqVO.getEvidenceUrl())
                .betweenIfPresent(ProjectsDO::getCreateTime, reqVO.getCreateTime())
                .eqIfPresent(ProjectsDO::getRemark, reqVO.getRemark())
                .orderByDesc(ProjectsDO::getId));
    }

    @Select("SELECT * FROM digital_projects WHERE id = #{id}")
    ProjectsDO selectByIdWithRawSQL(@Param("id") Integer id);

    @Select("SELECT evidence_url FROM digital_projects WHERE id = #{id}")
    String getRawEvidenceUrl(@Param("id") Integer id);
}